#include "device.h"

// 设备驱动函数指针初始化
// 若底层不支持此函数，则将指针指向NULL
void device_init(device_t *device, uint32 device_select)
{
    device->led.init = led_init;
    device->led.blink = led_blink;
    device->oled.init = OledInit;
    device->oled.clear = OledCls;
    device->oled.show_ch = OledShow6x8Char;
    device->oled.show_str = OledShow6x8Str;
    device->oled.show_value_int = OledPrintValueI;
    device->oled.show_value_float = OledPrintValueF;
    device->oled.show_img = OledPrintImage;
    device->oled.draw_bmp = OledDrawBMP;
    device->key.init = key_init;
	device->key.tim_check = key_tim_check;
    device->key.scan = key_scan;
	device->key.tim_scan = key_tim_scan;
    device->buzzer.init = buzzer_init;
    device->buzzer.beep = buzzer_beep;
    device->timer.init = tim_int_init;
    device->motor.init = motor_pwm_init;
    device->motor.output_4ch = motor_pwm_output_4ch;
    device->mpu6050.init = mpu6050_init;
    device->mpu6050.get_raw_data = mpu6050_get_raw_data;
    device->mpu6050.data = &mpu6050_data;
    device->usart.init = usart_init;
    device->usart.send_message = usart_send_message;
    device->usart.receive_buffer = g_data_buffer_share;
    
    if (device_select & LED) device->led.init();
    if (device_select & OLED) device->oled.init();
    if (device_select & KEY) device->key.init();
    if (device_select & BUZZER) device->buzzer.init();
    if (device_select & TIMER) device->timer.init(device->para.timer_frequency);
    if (device_select & MOTOR) device->motor.init(device->para.motor_pwm_period, device->para.motor_pwm_frequency);
    if (device_select & MPU6050) device->mpu6050.init();
    if (device_select & USART) device->usart.init(device->para.usart_baud);
}



